<template>
	<view>
		<!-- 头部 -->
<!-- 		<u-navbar is-back title="食材分类" :bgColor="background" title-color="#fff" :border-bottom="false"
			back-icon-color="#fff">
		</u-navbar> -->
		<!-- 分段器 -->
		<view class="slide-button">
			<view class="slide-button-item">
				<u-subsection :list="list" :current="current" active-color="#ef7d2b" bg-color="transparent"
					inactive-color="#fff" @change="sectionChange">
				</u-subsection>
			</view>
		</view>
		<!-- 搜索 -->
		<view class="search">
			<view class="search-item">
				<u-search placeholder="想吃什么搜这里,如麻婆豆腐" v-model="keyword" shape="square" :clearabled="true"
					:show-action="false" search-icon-color="#ef7d2b" input-align="center"></u-search>
			</view>
		</view>
		<view class="content">
			<scroll-view scroll-y class="aside">
				<view class="aside-item" v-for="(item,index) in sortList" :key="item._id" @tap="changeCategory(index)"
					:class="{active:activeIndex==index}">
					<text>{{item.cat_name}}</text>
				</view>
			</scroll-view>
			<scroll-view scroll-y class="article">
				<view class="article-container">
					<text class="article-text title">{{sortList[activeIndex].cat_name}}</text>
					<view class="article-content">
						<view class="article-item-container" v-for="item in categories[activeIndex].children"
							:key="item.cat_id">
							<image :src="item.cat_icon" mode="" class="article-item-image"></image>
							<text class="article-item-text">{{item.cat_name}}</text>
						</view>
					</view>
				</view>
			</scroll-view>

		</view>
		
	</view>
</template>

<script>
	import {
		createNamespacedHelpers
	} from "vuex"
	const {
		mapState,
		mapMutations
	} = createNamespacedHelpers("sortModule")
	export default {
		data() {
			return {
				status: true,
				background: 'linear-gradient(45deg, rgb(238, 129, 49), rgb(240, 154, 55))',
				list: [{
						name: '分类'
					},
					{
						name: '食材'
					}
				],
				current: 0,
				keyword: "",
				categories: [],
				activeIndex: 0,
			}
		},
		methods: {
			...mapMutations(['sort']),
			async findData() {
				//分类
				let sortmeau = await this.$api.sort.sortData()
				let sortMessage = sortmeau.data.message
				let indexdata = {
					sortMessage
				}
				this.sort(indexdata)
				console.log(this.sortList);
			},
			sectionChange(index) {
				this.curNow = index;
			},
			changeIndex(index) {
				console.log(index);
				this.sortIndex = index
			}


		},
		computed: {
			...mapState(['sortList'])
		},
		created() {
			this.findData()
		}
	}
</script>

<style lang="scss" scoped>
	.slide-button {
		background-image: linear-gradient(45deg, rgb(238, 129, 49), rgb(240, 154, 55));
		width: 100%;

		.slide-button-item {
			width: 380rpx;
			margin: 0 auto;
		}
	}

	.search {
		height: 100rpx;
		background-image: linear-gradient(45deg, rgb(238, 129, 49), rgb(240, 154, 55));
		overflow: hidden;

		.search-item {
			width: 692rpx;
			margin: 20rpx auto 0;
		}
	}

	//隐藏滚动条
	scroll-view ::-webkit-scrollbar {
		width: 0;
		height: 0;
		background-color: transparent;
	}


	.content {
		display: flex;

		.aside {
			width: 180rpx;
			height: calc(100vh - 170rpx);
			flex-shrink: 0;


			.aside-item {
				width: 100%;
				height: 130rpx;
				line-height: 130rpx;
				text-align: center;
				background-color: #f6f6f6;
			}

			.active {
				background-color: #fff;
			}
		}

		.article {
			flex-grow: 1;
			height: calc(100vh - 170rpx);

			.article-container {
				margin-top: 20rpx;

				.article-text {
					margin-top: 30rpx;
					margin-left: 20rpx;
					color: #cbcbcb;
				}

				.article-content {
					padding: 0 32rpx;
					display: flex;
					flex-wrap: wrap;
					margin-bottom: 20rpx;

					.article-item-container {
						display: flex;
						flex-direction: column;
						justify-content: center;
						align-items: center;
						width: 100rpx;
						height: 200rpx;
						margin-right: 100rpx;

						&:nth-child(3n) {
							margin-right: 0;
						}

						.article-item-image {
							width: 100rpx;
							height: 100rpx;
						}

						.article-item-text {
							margin-top: 25rpx;
							font-size: 25rpx;
						}
					}
				}
			}
		}
	}
</style>
